from datastructure.link import list
from threading import Condition
from threading import Lock
from threading import Thread

lock = Lock()
cond = Condition(lock)
l = list()


def consumer(*args, **kwargs):
    print("The consumer is ready to read.")
    while True:
        cond.acquire()
        print("Hello")
        if l:
            data = l.pop()
            print("\n" + data)
        else:
            """
               1, 初始化
               2，释放锁
               3，等待
               4，获得锁
            """
            cond.wait()
        cond.release()


consume_thread = Thread(target=consumer)
consume_thread.start()

while True:
    data = input("Please enter: ")
    cond.acquire()
    l.append(data)
    """
        RELASE
        1，发送通知信号
        2，获得锁
    """
    cond.notify()
    cond.release()
